<template>
  <div class="cartcontrol" v-show="this.refresh">
    <transition name="move">
      <div class="cart-dec icon-remove_circle_outline" v-show="getCount.count>0" @click="decCart" ></div>
    </transition>
    <div class="cart-count" v-show="getCount.count>0" :class="{change:valueChange}">{{getCount.count}}</div>
    <div class="cart-add icon-add_circle" @click="addCart"></div>
  </div>
</template>

<script>
  import {mapActions,mapGetters} from "vuex"
  export default {
    props:{
      obj:{}
    },
    data() {
      return {
        count: 0,
        refresh:'false'
      }
    },
    computed:{
      ...mapGetters(["allGoods","valueChange"]),
      getCount(){
        return this.allGoods.find(f=>f.name===this.obj.name)
      }
    },
    methods: {
      ...mapActions(['addToCart','devToCart']),
      addCart () {
//        this.count++
        let obj=this.obj
        this.addToCart({obj})
        if(this.getCount.count>0)
        {
          this.refresh='ture'
        }
      },
      decCart () {
        let obj=this.obj
        //this.count--
        this.devToCart({obj})
        if(this.getCount.count<=0)
        {
          this.refresh='false'
        }
      },
    }
  }
</script>

<style lang="less" scoped>
  .cartcontrol {
    font-size: 0;
    .cart-dec {
      transition: all 0.4s linear;
      &.move-enter, &.move-leave-to {
        opacity: 0;
        transform: translate3D(24px, 0, 0) rotate(180deg);
      }
    }
    .cart-dec, .cart-add {
      padding: 6px;
      display: inline-block;
      line-height: 24px;
      font-size: 24px;
      color: rgb(0, 160, 220);
    }
    .cart-count {
      display: inline-block;
      padding-top: 7px;
      vertical-align: top;
      text-align: center;
      line-height: 24px;
      font-size: 10px;
      color: rbg(147, 153, 159);
    }
  }
</style>
